package com.ruoyi.web.controller.production.fertilizer;

import java.util.List;

import com.ruoyi.common.annotation.PropertyInject;
import com.ruoyi.common.enums.InjectType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.production.domain.fertilizer.FertilizerAmount;
import com.ruoyi.production.service.fertilizer.IFertilizerAmountService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 化肥量Controller
 *
 * @author ruoyi
 * @date 2021-07-12
 */
@RestController
@RequestMapping("/production/fertilizerAmount")
public class FertilizerAmountController extends BaseController
{
    @Autowired
    private IFertilizerAmountService fertilizerAmountService;

    /**
     * 查询化肥量列表
     */
    @PreAuthorize("@ss.hasPermi('production:fertilizerAmount:list')")
    @GetMapping("/list")
    public TableDataInfo list(FertilizerAmount fertilizerAmount)
    {
        startPage();
        List<FertilizerAmount> list = fertilizerAmountService.selectFertilizerAmountList(fertilizerAmount);
        return getDataTable(list);
    }

    /**
     * 导出化肥量列表
     */
    @PreAuthorize("@ss.hasPermi('production:fertilizerAmount:export')")
    @Log(title = "化肥量", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FertilizerAmount fertilizerAmount)
    {
        List<FertilizerAmount> list = fertilizerAmountService.selectFertilizerAmountList(fertilizerAmount);
        ExcelUtil<FertilizerAmount> util = new ExcelUtil<FertilizerAmount>(FertilizerAmount.class);
        return util.exportExcel(list, "化肥量数据");
    }

    /**
     * 获取化肥量详细信息
     */
    @PreAuthorize("@ss.hasPermi('production:fertilizerAmount:query')")
    @GetMapping(value = "/{fertilizerAmountId}")
    public AjaxResult getInfo(@PathVariable("fertilizerAmountId") Long fertilizerAmountId)
    {
        return AjaxResult.success(fertilizerAmountService.selectFertilizerAmountById(fertilizerAmountId));
    }

    /**
     * 新增化肥量
     */
    @PreAuthorize("@ss.hasPermi('production:fertilizerAmount:add')")
    @Log(title = "化肥量", businessType = BusinessType.INSERT)
    @PostMapping
    @PropertyInject(type = InjectType.Insert)
    public AjaxResult add(@RequestBody FertilizerAmount fertilizerAmount)
    {
        return toAjax(fertilizerAmountService.insertFertilizerAmount(fertilizerAmount));
    }

    /**
     * 修改化肥量
     */
    @PreAuthorize("@ss.hasPermi('production:fertilizerAmount:edit')")
    @Log(title = "化肥量", businessType = BusinessType.UPDATE)
    @PutMapping
    @PropertyInject(type = InjectType.Update)
    public AjaxResult edit(@RequestBody FertilizerAmount fertilizerAmount)
    {
        return toAjax(fertilizerAmountService.updateFertilizerAmount(fertilizerAmount));
    }

    /**
     * 删除化肥量
     */
    @PreAuthorize("@ss.hasPermi('production:fertilizerAmount:remove')")
    @Log(title = "化肥量", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fertilizerAmountIds}")
    public AjaxResult remove(@PathVariable Long[] fertilizerAmountIds)
    {
        return toAjax(fertilizerAmountService.deleteFertilizerAmountByIds(fertilizerAmountIds));
    }
}
